home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d2
/
setf.arc
/
SETF.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1990-03-31
|
13KB
|
411 lines
Program setf;
{
Program : setf.pas
Date : 03/30/90
Revision : 2.1
Description : Provides a means of setting DOS level function keys.
Caveats : F1, 3, 9 and 10 should not be set because of possible
interference with DOS and 4DOS.
Compiler : Turbo Pascal 5.0 with TP&ASM Inline Assembly Utility
}
Uses
Crt, Dos; {Unit found in TURBO.TPL}
{$I keydefs.inc}
Const
SCCS_ID = '@(#)setf.pas, 09-30-90, Revision 2.1\n';
Type
MaxKeys = 1..40; { Total number of keys to program }
StringType = String[80]; { Some other general types }
StringLength = String[79];
IntType = Integer;
ConfigKeys = ARRAY [MaxKeys] of StringLength; { Struct for keys }
Var
InFileName :File of ConfigKeys; { File for saving keys }
Found, { Parameter found indicator }
Change, { Key changed indicator }
ResultIO :Boolean; { Result of file open test }
SCCSID,
FkeyS,
Fname :String[40];
FkeyConfig :ConfigKeys;
V_Mode, { Video Mode result }
KeyHit, { Some other general types }
Count2,
Count :Integer;
Param_Str,
Response2,
Response :StringType;
Resp,
Fkey :Char;
{$I getkey.inc} { Include to get an input key }
{$I getstring.inc} { Include to get a string }
{===========================================================================}
{ This procedure is used to display a help screen under cetain conditions }
Procedure PrintHelp;
Begin
ClrScr;
Writeln;
Writeln('This program allows the setting of all 40 DOS function keys.');
Writeln;
Writeln;
Writeln('Usage: setf [ - or / ] [ hidcl ] [ filename ]');
Writeln;
Writeln('Where: c - configure function keys');
Writeln(' l - load function keys');
Writeln(' d - display function key settings');
Writeln(' h - display this help screen');
Writeln(' i - program information');
Writeln(' filename - key configuration file');
Writeln(' DEFAULT is C:\Fkeys.cfg');
Writeln;
Writeln('NOTE: The Extended ANSI driver must be installed');
Writeln(' for this program to work properly.')
End;
{===========================================================================}
{ Used to get the filename of the configuration file. Defaults to fkeys.cfg }
Procedure GetFilename;
Begin
If ParamCount < 2 Then { if no filename input }
Fname := 'c:\Fkeys.cfg' { assign default filename }
Else
Fname := ParamStr(2); { otherwise get filename from command line }
Assign(InFileName,Fname); { Assign the file and open file }
{$I-}
Reset(InFileName);
ResultIO := (IOResult = 0);
{$I+}
If not ResultIO Then { if not open now }
If (Param_Str[2] = 'C') Then { and configuring keys }
Rewrite(InFileName) { create the file }
Else
Begin
Writeln('Unable to open file ',Fname); { or give error }
Halt
End
Else
If not EOF(InFileName) Then { or read in file }
Read(InFileName, FkeyConfig)
End;
{===========================================================================}
{ This procedure is used to configure the keys in the configuration file. }
Procedure ConfigureKeys;
Begin
GetFilename;
Response := '';
While not(Response = ESC) Do { Configure keys until user quits }
Begin
ClrScr;
Write('Enter a Function Key to setup or ESC to quit : ');
Fkey := Getkey;
If Fkey = ESC Then
Exit;
If (ord(Fkey) IN[187..196,212..241]) Then { is it a function key }
Begin
KeyHit := (ord(Fkey) - 186); { convert the keycode }
Fkey := chr(ord(Fkey) - 128);
str(ord(Fkey):2, FkeyS);
Resp := 'y';
If KeyHit IN[1,3,9,10] Then { test for F1, 3, 9, or 10 }
Begin
Writeln;
Writeln('Changing this key can');
Writeln('cause SERIOUS interference with DOS . . .');
Writeln;
Writeln('Do you wish to continue ? (y/n)');
Resp := Getkey;
If Resp IN['y','Y'] Then { Get function key to setup }
Begin
ClrScr;
Write('Enter a Function Key to setup : ')
End
End;
If Resp IN['y','Y'] Then
Begin
If KeyHit > 10 then { Is key normal function key }
KeyHit := KeyHit - 15; { or is it extended function key }
Case KeyHit of
{ DISPLAY THE FUNCTION KEY TO SETUP }
1..10 : Writeln('F',KeyHit);
11..20 : Writeln('Shift F',KeyHit - 10);
21..30 : Writeln('Ctrl F',KeyHit - 20);
31..40 : Writeln('Alt F',KeyHit - 30);
End; {EndCase}
Writeln(FkeyConfig[KeyHit]); { Display old setting }
Writeln;
Writeln('Enter the command you wish to perform ');
Writeln('- to Delete ESC to leave unchanged ');
Response2 := GetString(Response, 67); { GET SETUP STRING }
{ - deletes else store the new setup }
If (Response2 <> '-') and (Response2 <> ESC) Then
Begin
Change := TRUE; { Set key changed }
FkeyConfig[KeyHit] := '[0;'+FkeyS+';"'+Response2+'";13p'
End
Else
If Response = '-' Then
Begin
Change := TRUE; { set key changed and delete key }
FkeyConfig[KeyHit] := '[0;'+Fkeys+';0;'+Fkeys+';p'
End
Else
Response := ' ' { else do nothing and reset response }
End;
{ Endif KeyHit }
End
End
End;
{===========================================================================}
{ This procedure reads the configuration file and loads the fkey functions }
Procedure SetFunctions;
Var
Key_Code :String[80]; { String for setting up key }
Begin
GetFilename;
For Count := 1 to 40 Do
If FkeyConfig[Count] <> NULL Then
Begin
{ generate string to output }
Key_Code := Concat(ESC, FkeyConfig[Count], '$');
Assembly
push ds ;output the key with assembly
push ss ;since Pascal can't do it right
pop ds
lea dx,Key_Code ;string to setup
inc dx
mov ah,09h ;use int 21 to output it
int 21h
pop ds
End;
End;
Writeln;
Writeln('Function keys set via ',Fname) { tell user we're done }
End;
{===========================================================================}
{ This procedure displays the function key settings. }
Procedure DispFunctions;
Var Count2 :Integer;
Begin
GetFileName;
{ Search and display Funtion Keys }
For Count := 1 to 40 Do
If (FkeyConfig[Count][1] <> NULL) and (FkeyConfig[Count][8] <> ';')
and (FkeyConfig[Count][9] <> ';') Then Begin
Count2 := 1;
While FkeyConfig[Count][Count2] <> '"' Do
Count2 := Count2 + 1;
Count2 := Count2 + 1;
If FkeyConfig[Count][Count2] <> '"' Then
Begin
Writeln;
Case Count of
1..10 : Write(' F',Count:2,' = ');
11..20 : Write('SF',(Count - 10):2,' = ');
21..30 : Write('CF',(Count - 20):2,' = ');
31..40 : Write('AF',(Count - 30):2,' = ');
End;
{ Display Function Key Found }
End;
While Count2 < 79 Do
If FkeyConfig[Count][Count2] <> '"' Then
Begin
Write(FkeyConfig[Count][Count2]);
Count2 := Count2 + 1
End
Else
Count2 := 79
End;
Writeln;
End;
{===========================================================================}
{ This procedure tests the paramaters and processes command accordingly }
Procedure ProcessParams;
Begin
If (Param_Str[2] = 'H') Then
PrintHelp;
If (Param_Str[2] = 'I') or (Param_Str[2] = 'H') Then Begin
Found := TRUE;
Writeln;
Writeln(' Version - 2.1');
Writeln(' Compiler - Turbo Pascal Ver. 5.0');
Writeln(' - TP&Asm InLine Assembly Utility');
Writeln(' Purpose - Provides means for setting DOS function keys');
Writeln;
End;
For Count := 1 to 40 Do { Clear out the buffer area }
For Count2 := 0 to 79 Do
FkeyConfig[Count][Count2] := NULL;
Change := FALSE;
If (Param_Str[2] = 'L') Then Begin { -l loads the keys }
Found := TRUE;
SetFunctions
End;
If (Param_Str[2] = 'D') Then Begin { -d displays the setup file }
Found := TRUE;
DispFunctions
End;
If (Param_Str[2] = 'C') Then Begin { -c configures the keys }
Found := TRUE;
ConfigureKeys;
If Change = TRUE Then Begin { save only if change made }
Resp := NULL;
Writeln;
Write('Save Changes ? '); { Save config to disk }
Resp := Getkey;
If Resp IN['Y','y'] Then Begin
Rewrite(InFileName);
Write(InFileName, FkeyConfig);
Close(InFileName);
Writeln;
Writeln('Keys saved to ',Fname)
End;
Writeln; { Setfunctions before exit }
Write('Set function keys now ? ');
Resp := Getkey;
Writeln;
Writeln;
If Resp IN['Y','y'] Then
SetFunctions
End;
End;
End;
{===========================================================================}
Begin { Main Program Module }
SCCSID := SCCS_ID;
Found := FALSE;
Assembly { Check Video Mode }
mov ax,0f00h
int 10h
xor ah,ah
mov V_Mode,ax
End;
If V_Mode IN[0..3] Then { Check for snow if CGA }
CheckSnow := TRUE;
CheckBreak:= TRUE; { Turn break check on }
Param_Str := ParamStr(1); { Get function parameter }
Param_Str[2] := UpCase(Param_Str[2]);
If ParamCount = 0 Then
Begin
Writeln;
Writeln('This program allows setting of all 40 of the function');
Writeln('keys available to DOS. ');
End;
{ Endif }
If ParamCount > 0 Then Begin
ProcessParams;
If (not Found) Then Begin
Writeln('setf: error: Unknown option: ',Param_Str[2]);
Writeln('setf: usage: setf [/ or -] [ hidcl ] [ filename ]');
Writeln(' setf -h or HELP');
End;
End Else Begin
Writeln;
Writeln('usage: setf [ / or - ] [ hidcl ] [ filename ]');
Writeln(' setf -h for HELP');
Writeln;
Writeln('NOTE: The Extended ANSI driver must be installed.')
End;
End.